//package org.ricks.robot;
//
//import org.ricks.common.conf.RicksPropertiesLoader;
//import org.ricks.common.lang.Logger;
//import org.ricks.common.utils.ThreadUtils;
//import org.ricks.net.AioSession;
//import org.ricks.net.handler.HeartPlugin;
//import org.ricks.net.transport.kcp.KcpBootstrap;
//import org.ricks.net.transport.kcp.KcpChannel;
//import org.ricks.net.transport.kcp.KcpSession;
//import org.ricks.protocol.ByteBuf;
//import org.ricks.robot.business.RobotAction;
//import proto.common.FProto;
//import proto.common.PlayerAccount;
//
//import java.io.IOException;
//import java.net.InetSocketAddress;
//import java.net.SocketAddress;
//import java.util.concurrent.Executors;
//import java.util.concurrent.ScheduledExecutorService;
//import java.util.concurrent.TimeUnit;
//
//public class RobotRun {
//
//
//    public static ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(32);
//    public static int robotCount = 1000;
//    //分钟
//    public static int robotRunTime = 24 * 60;
//    //一个轮回 每个机器人说话多少次
//    public static int robotChatCount = 100;
//    //一个轮回每个机器人单抽次数
//    public static int robotGacha1Count = 100;
//    //一个轮回每个机器人10连抽次数
//    public static int robotGacha10Count = 100;
//    //轮回每个机器人杀怪次数
//    public static int robotKillMonsterCount = 100;
//    //轮回每个机器人采集次数
//    public static int robotCollectCount = 100;
//    //角色养成模块，角色提升等级
//    public static boolean robotLoginStrategy = false;
//
//    public static String gatewayIp;
//    public static int port;
//
//    public static void main(String[] args) throws IOException {
//        RicksPropertiesLoader.loadingProperties();
//        robotCount = RicksPropertiesLoader.toIntOrDefault("robot.count", 1000);
//        robotRunTime = RicksPropertiesLoader.toIntOrDefault("robot.run.time", 24 * 60);
//
//        robotChatCount = RicksPropertiesLoader.toIntOrDefault("robot.chat.count", 0);
//        robotGacha1Count = RicksPropertiesLoader.toIntOrDefault("robot.gacha1.count", 100);
//        robotGacha10Count = RicksPropertiesLoader.toIntOrDefault("robot.gacha10.count", 100);
//        robotKillMonsterCount = RicksPropertiesLoader.toIntOrDefault("robot.killMonster.count", 100);
//        robotCollectCount = RicksPropertiesLoader.toIntOrDefault("robot.collect.count", 100);
//        robotLoginStrategy = RicksPropertiesLoader.toBool("robot.login.strategy");
//
//         gatewayIp = RicksPropertiesLoader.get("gateway.ip");
//         port = RicksPropertiesLoader.toIntOrDefault("gateway.port", 29890);
//
//         Logger.info("开始压测 -- 压测目标地址：" + gatewayIp + ":" + port + " , robotCount:" + robotCount + " , robotRunTime:" + robotRunTime + " , robotChatCount:" + robotChatCount + " , robotGacha1Count:" + robotGacha1Count + " , robotGacha10Count:" + robotGacha10Count + " , robotKillMonsterCount:" + robotKillMonsterCount + " , robotCollectCount:" + robotCollectCount);
//
//        KcpProtocol kcpProtocol = new KcpProtocol();
//        KcpHandler kcpHandler = new KcpHandler();
//
//        KcpBootstrap bootstrap = new KcpBootstrap(kcpProtocol, kcpHandler);
//        bootstrap.setReadBufferSize(1024 * 100);
////        bootstrap.setThreadNum(4);
//        Runnable task = () -> Monitor.printInfo("60s--");
//        scheduledExecutorService.scheduleAtFixedRate(task, 1, 60, TimeUnit.SECONDS);
//        scheduledExecutorService.schedule(() -> RobotAction.robotStop(),  robotRunTime, TimeUnit.MINUTES);
//
//        for (int i = 1; i <= 10 ; i++) {
//            int finalI = i;
//            String robotAccount = "ricks-robot"+System.currentTimeMillis()+"-" + finalI;
//            KcpSession session  = createKcp(bootstrap, robotAccount);
//            login(session, robotAccount);
//            ThreadUtils.sleep(1000L);
//        }
//    }
//
//    public static KcpSession createKcp(KcpBootstrap bootstrap, String account) throws IOException {
//        KcpChannel channel = (KcpChannel) bootstrap.open();
//        SocketAddress socketAddress = new InetSocketAddress("192.168.18.142", 29890);
//        KcpSession session = channel.createAndCacheSession(socketAddress,Math.abs(account.hashCode()));
//        RobotManager.login(session, account);
//        return session;
//    }
//
//
//    private static void login(KcpSession session ,  String robotAccount) {
//        Monitor.addActionRequest(session, FProto.Action.Login);
//        RobotInfo robotInfo = RobotManager.get(session);
//        robotInfo.requestTimeMap.put(FProto.Action.Login, System.currentTimeMillis());
//        PlayerAccount playerAccount = PlayerAccount.newBuilder()
//                .setAccount(robotAccount)
//                .build();
////        Logger.info(RobotManager.get(session).toString() + " 开始请求登录");
//        FProto fProto = FProto.newBuilder()
//                .setKey(FProto.Key.Player)
//                .setAction(FProto.Action.Login)
//                .setAccount(playerAccount)
//                .build();
//
//        byte[] data = fProto.toByteArray();
//
//        ByteBuf buf = new ByteBuf(1024);
//        buf.writeByte((byte) 0x03);
//        buf.writeBytes(data);
//
//        session.send(buf.toArray());
//    }
//
//}
